from quart import Quart

import config_dev
import config_prod
import routes.idx_route as idx_route
from src import faiss_index

app = Quart(__name__)
env = app.config.get('QUART_ENV', None)
if env == 'production':
    app.config.from_object(config_prod.Config)
    print('--------prod active!--------', env)
else:
    app.config.from_object(config_dev.Config)
    print('--------dev active!--------', app.config.get('ENV', None))

# 初始化加载
local_vector_path = app.config.get('LOCAL_VECTOR_PATH', None)
if local_vector_path is not None and local_vector_path != '':
    print('init index from local vector,path=', local_vector_path)
    faiss_index.post_construct('default', app.config.get('DIM', 64),
                               app.config.get('INDEX_FACTORY', 'IVF128,Flat'), None, local_vector_path)

app.register_blueprint(idx_route.idx_bp)

if __name__ == '__main__':
    app.run()


@app.route('/')
async def hello_faiss():
    return 'Hello faiss-quart'
